﻿/*
Copyright © 2011 François Karman

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

See <license.txt> for the complete license of the software.
*/

using System.Windows;
using System.Windows.Controls;
using NUnit.Framework.Api;

namespace NUnit.Phone.Gui
{
    /// <summary>
    /// Displays the list of all the available and loaded tests.
    /// </summary>
    public partial class TestList : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the TestList class.
        /// </summary>
        public TestList()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Provides the <see cref="MainView"/> associated with the
        /// test list.
        /// </summary>
        protected MainView MainView
        {
            get { return this.RetrieveParent<MainView>(); }
        }

        /// <summary>
        /// Called when one of the children is clicked - refresh the page
        /// to display the details of this child.
        /// </summary>
        /// <param name="sender">The parameter is not used.</param>
        /// <param name="e">The parameter is not used.</param>
        private void OnChildClick(object sender, RoutedEventArgs e)
        {
            ITest test = ((Button)sender).DataContext as ITest;
            if (test == null)
            {
                return;
            }

            this.MainView.Reload("testid", test.Id.ToString());
        }
    }
}
